package com.example.blogsystem.common;

import com.example.blogsystem.entity.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 用户登录的相关操作
 */
public class UserSessionUtils {

    public static UserInfo getSessionUser(HttpServletRequest request) {
        // 1.获取当前的用户(从session中获取)
        HttpSession session = request.getSession(false);
        if (session == null) {
            return null;
        }
        UserInfo userInfo = (UserInfo) session.getAttribute(GlobalVariable.USER_SESSION_KEY);
        return userInfo;
    }
}
